<style lang="scss" scoped="">
  @import '../../styles/variables';

</style>
<template>
  <div class="page-main">
    <div class="list-bar-tools">

      <div>
        <div class="flex">
          <el-input placeholder="" v-model="filter.nodeName" class="list-bar-tools-input" size="mini" clearable="">
            <template slot="prepend">节点名称</template>
          </el-input>
        </div>
      </div>
    </div>
    <el-table
      :data="nodeList"
      border
      style="width: 100%">
      <el-table-column
        prop="nodeName"
        label="节点名称">
      </el-table-column>
      <el-table-column
        prop="fromRegisterNodeName"
        label="注册操作来源">
      </el-table-column>
      <el-table-column
        prop="lastRegisterTime"
        label="上一次注册时间">
      </el-table-column>
      <el-table-column
        prop="lastCancelTime"
        label="上一次注销时间">
      </el-table-column>
      <el-table-column
        prop="fromCancelNodeName"
        label="注销操作来源">
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 50, 100]"
        :page-size="filter.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="nodeCount">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import utils from '@/utils/utils';
  import {nodeService} from '@/api/index';
  import {mapGetters} from 'vuex';

  export default {
    data() {
      return {
        filter: {
          pageNo: 1,
          pageSize: 10,
          start: 0,
          nodeName: ''
        },
        nodeCount: 0,
        nodeList: []
      };
    },
    computed: {},
    watch: {
      'filter': {
        handler: function () {
          this.getNodeList();
        },
        deep: true,
        immediate: true
      }
    },
    components: {},
    methods: {
      handleCurrentChange(currentPageNo) {
        this.filter.start = (currentPageNo - 1) * this.filter.pageSize;
      },
      handleSizeChange(pageSize) {
        this.filter.pageSize = pageSize;
        localStorage.setItem('node-last-time-page-size', pageSize);

      },
      getNodeList() {
        nodeService.getLastTimePage(this.filter).then(res => {
          this.nodeCount = res.data.total;
          this.nodeList = res.data.rows;
        });
      }
    },
    created() {
      let oldPageSize = localStorage.getItem('node-last-time-page-size');
      if (!oldPageSize) {
        oldPageSize = 10;
      }
      this.filter.pageSize = Math.floor(oldPageSize);
    },
    mounted() {
    }
  };
</script>
